package com.fy.fyspace.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.fy.fyspace.model.entity.Picture;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.Date;
import java.util.List;

/**
 * @author fwq
 * @description 针对表【picture(图片表)】的数据库操作Mapper
 * @createDate 2024-12-19 12:32:35
 * @Entity generator.domain.Picture
 */
@Mapper
public interface PictureMapper extends BaseMapper<Picture> {

  /**
   * 查询所有不重复的分类
   */
  @Select("SELECT DISTINCT category FROM picture WHERE is_delete = 0 AND category IS NOT NULL AND category != ''")
  List<String> selectDistinctCategories();

  /**
   * 查询所有不重复的标签
   */
  @Select("SELECT DISTINCT UNNEST(string_to_array(tags, ',')) as tag FROM picture WHERE is_delete = 0 AND tags IS NOT NULL AND tags != ''")
  List<String> selectDistinctTags();

  @Update("UPDATE picture SET isDelete = #{isDelete}, updateTime = #{updateTime} WHERE id = #{picId}")
  void updateDelStatusById(Long picId, Integer isDelete, Date updateTime);
}
